#!/usr/bin/env python

from PySide.QtCore import *
from QtMobility.Location import *
import sys

class ShowCoordinates:
    def __init__(self):
        self.source = QGeoPositionInfoSource.createDefaultSource(None)
        if self.source is not None:
            self.source.setUpdateInterval(35000)
            self.source.positionUpdated.connect(self.positionUpdated)
            self.source.updateTimeout.connect(self.updateTimeout)
            self.source.requestUpdate(35000)


    def positionUpdated(self, update):
        print "{latitude\":%s, longitude\":%s, accuracy\":1}" % (update.coordinate().latitude(), update.coordinate().longitude())
        app.exit()

    def updateTimeout(self):
        lastLoc = self.source.lastKnownPosition()
        print "Location update timed Out. Last known position {latitude\":%s, longitude\":%s, accuracy\":0}" % (lastLoc.coordinate().latitude(), lastLoc.coordinate().longitude())
        app.exit()


if __name__ == "__main__":

    app = QCoreApplication([])
    reader = ShowCoordinates()
    sys.exit(app.exec_())


